package org.hw;

import org.Entity.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class MainTest01 {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
        Class<Student> studentClass = Student.class;

        Constructor<Student> constructor = studentClass.getDeclaredConstructor();
        Student student = constructor.newInstance();

        Method setName = studentClass.getMethod("setName", String.class);
        Method setAge = studentClass.getMethod("setAge", int.class);
        Method setWeight = studentClass.getMethod("setWeight", double.class);

        setName.invoke(student, "张三");
        setAge.invoke(student, 18);
        setWeight.invoke(student, 60.0);

        student.show();

        Constructor<?> constructorClass = studentClass.getConstructor(String.class,int.class,double.class);
        Student student1 = (Student) constructorClass.newInstance("李四",20,70.0);
        student1.show();

    }
}
